package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.BookUser;
import com.ruoyi.project.system.service.IBookUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户信息管理Controller
 *
 * @author ruoyi
 * @date 2020-03-09
 */
@RestController
@RequestMapping("/system/book_user")
public class BookUserController extends BaseController
{
    @Autowired
    private IBookUserService bookUserService;

    /**
     * 查询用户信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:book_user:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookUser bookUser)
    {
        startPage();
        List<BookUser> list = bookUserService.selectBookUserList(bookUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:book_user:export')")
    @Log(title = "用户信息管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BookUser bookUser)
    {
        List<BookUser> list = bookUserService.selectBookUserList(bookUser);
        ExcelUtil<BookUser> util = new ExcelUtil<BookUser>(BookUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取用户信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:book_user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bookUserService.selectBookUserById(id));
    }

    /**
     * 新增用户信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:book_user:add')")
    @Log(title = "用户信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookUser bookUser)
    {
        return toAjax(bookUserService.insertBookUser(bookUser));
    }

    /**
     * 修改用户信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:book_user:edit')")
    @Log(title = "用户信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookUser bookUser)
    {
        return toAjax(bookUserService.updateBookUser(bookUser));
    }

    /**
     * 删除用户信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:book_user:remove')")
    @Log(title = "用户信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookUserService.deleteBookUserByIds(ids));
    }
}